<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-card class="search-card">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        class="formBox"
        label-width="90px"
      >
        <el-form-item label="收费项目" prop="itemName">
          <el-input placeholder="请输入收费项目" v-model="queryParams.itemName" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >
            搜索
          </el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置
          </el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 按钮 -->
    <el-card class="box-card" style="margin-top: 10px">
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="buttonMethod(1)"
            v-hasPermi="['charge:feeStandardsProject:chargeSet:add']"
            >新增
          </el-button>
        </el-col>
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
    </el-card>
    <!-- 列表 -->
    <el-card class="table-card" style="margin-top: 10px">
      <el-table :data="dataList" stripe border>
        <el-table-column label="项目类型" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.subject_type" :value="scope.row.subjectType"/>
          </template>
        </el-table-column>
        <el-table-column label="收费项目名称" prop="itemName" />
        <el-table-column label="所属商户" prop="merchantName" />
        <el-table-column label="是否强制收费" prop="mandatoryStatus">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.mandatoryStatus == '1'">是</el-tag>
            <el-tag type="danger" v-if="scope.row.mandatoryStatus == '2'">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否卧具费" prop="bedFeeStatus">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.bedFeeStatus == '1'">是</el-tag>
            <el-tag type="danger" v-if="scope.row.bedFeeStatus == '2'">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="缴费顺序" prop="orderNum" />
        <el-table-column label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.closeStatus == '1'">启用</el-tag>
            <el-tag type="danger" v-if="scope.row.closeStatus == '2'">停用</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="创建时间" prop="createTime" />
        <el-table-column label="操作" width="260" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(2, scope.row)"
              v-hasPermi="['charge:feeStandardsProject:chargeSet:edit']"
              >修改
            </el-button>
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(5, scope.row)"
              v-if="scope.row.closeStatus == '1'"
              v-hasPermi="['charge:feeStandardsProject:chargeSet:edit']"
              >停用
            </el-button>
            <el-button
              size="mini"
              type="text"
              @click="buttonMethod(5, scope.row)"
              v-if="scope.row.closeStatus == '2'"
              v-hasPermi="['charge:feeStandardsProject:chargeSet:edit']"
              >启用
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 添加、编辑 -->
    <el-dialog :title="title" :visible.sync="status" width="50%">
      <el-form label-width="180px" label-position="right" size="small" class="formBox">
        <el-row class="mb_10">
          <el-col :span="20">
            <el-form-item label="项目类型：" class="is-required">
              <el-select
                v-model="queryForm.subjectType"
                placeholder="请选择项目类型"
                @keyup.enter.native="handleQuery"
                style="width: 100%"
              >
                <el-option label="代缴费" value="1" />
                <el-option label="学宿费" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item label="收费项目：" class="is-required">
              <el-input placeholder="请输入收费项目" v-model="queryForm.itemName">
              </el-input>
            </el-form-item>
            <el-form-item label="所属商户：" class="is-required">
              <el-select
                v-model="queryForm.merchantPkId"
                placeholder="请选择所属商户"
                @keyup.enter.native="handleQuery"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in selectMerchantData"
                  :key="dict.value"
                  :label="dict.merchantName"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="是否强制收费：" class="is-required">
              <el-radio-group v-model="queryForm.mandatoryStatus">
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="是否卧具费：">
              <el-radio-group v-model="queryForm.bedFeeStatus">
                <el-radio label="1">是</el-radio>
                <el-radio label="2">否</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="缴费顺序：" class="is-required">
              <el-input placeholder="请输入缴费顺序" v-model="queryForm.orderNum">
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="buttonMethod(3)">取 消</el-button>
        <el-button type="primary" @click="buttonMethod(4)">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  payFeeItemConfigList,
  payFeeItemConfigClose,
  payFeeItemConfigOpen,
  payFeeItemConfigPost,
  payFeeItemConfigPut,
} from "@/api/charge/bo";
import { selectMerchant } from "@/api/systemSet";
export default {
  name: "",
  dicts: ["subject_type"],
  data() {
    return {
      status: false,
      export_status: false,
      title: "",
      dataList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemName: null,
      },
      queryForm: {},
      total: 0,
      showSearch: true,
      date: [],
      selectMerchantData: [],
    };
  },
  created() {
    this.getList();
    this.selectMerchantFun();
  },
  methods: {
    // 获取列表数据
    getList() {
      var data = this.queryParams;
      payFeeItemConfigList(data).then((res) => {
        if (res.code == 200) {
          this.dataList = res.rows;
          this.total = res.total;
        }
      });
    },
    selectMerchantFun() {
      selectMerchant().then((res) => {
        if (res.code == 200) {
          this.selectMerchantData = res.data;
        }
      });
    },
    /**
     * 按钮点击事件处理方法
     */
    buttonMethod(options, value) {
      //options 等于 1
      if (options == 1) {
        this.queryForm = {};
        this.title = "添加项目标准收费";
        this.status = true;
      }
      //options 等于 2 关闭弹窗
      else if (options == 2) {
        this.queryForm = { ...value };
        this.title = "修改项目标准收费";
        this.status = true;
      }
      //options 等于 3 关闭弹窗
      else if (options == 3) {
        this.queryForm = {};
        this.title = "";
        this.status = false;
        this.export_status = false;
      }
      //
      else if (options == 4) {
        var data = this.queryForm;
        if (!data.subjectType) {
          this.$message.error("请选择项目类型");
        }
        if (!data.itemName) {
          this.$message.error("请输入收费项目");
        }
        if (!data.merchantPkId) {
          this.$message.error("请选择所属商户");
        }
        if (!data.mandatoryStatus) {
          this.$message.error("请选择是否强制收费");
        }
        // if (!data.bedFeeStatus) {
        //   this.$message.error("请选择是否卧具费");
        // }
        if (!data.orderNum) {
          this.$message.error("请选择缴费顺序");
        }
        if (data.id) {
          payFeeItemConfigPut(data).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.status = false;
              this.resetQuery();
            } else {
              that.$message.error(res.msg);
            }
          });
        } else {
          payFeeItemConfigPost(data).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.status = false;
              this.resetQuery();
            } else {
              that.$message.error(res.msg);
            }
          });
        }
      }
      // 5
      else if (options == 5) {
        // 关闭
        if (value.closeStatus == "1") {
          payFeeItemConfigClose(value.id).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.resetQuery();
            } else {
              that.$message.error(res.msg);
            }
          });
        }
        // 开启
        else if (value.closeStatus == "2") {
          payFeeItemConfigOpen(value.id).then((res) => {
            if (res.code == 200) {
              this.$message.success(res.msg);
              this.resetQuery();
            } else {
              that.$message.error(res.msg);
            }
          });
        }
      }
    },
    /**
     * 处理查询请求
     *
     * 将查询参数中的页码重置为1，并调用getList方法获取列表数据
     */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /**
     * 重置查询表单并重新执行查询操作
     */
    resetQuery() {
      this.date = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        itemName: null,
      };
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style scoped>
.width_100 {
  width: 100%;
}
</style>
